import 'package:food_hub_app/models/moment.dart';
import 'package:food_hub_app/utils/http_util.dart';
import 'package:food_hub_app/utils/index.dart';

Future<bool> addMomentApi(Moment moment) {
  return HttpUtil().post<bool>("/moment", data: moment);
}

Future<bool> updateMomentApi(int id, Moment moment) {
  return HttpUtil().put<bool>("/moment/$id", data: moment);
}

Future<bool> deleteMomentApi(int id) {
  return HttpUtil().delete<bool>("/moment/$id");
}

Future<List<Moment>> queryMomentListApi() {
  return HttpUtil().get<List<Moment>>(
    "/moment",
    converter: (data) => convertListResponse<Moment>(data, Moment.fromJson),
  );
}

Future<PageMoment> queryMomentByPageApi(int currentPage, int pageSize) {
  return HttpUtil().get<PageMoment>(
    "/moment/page",
    queryParameters: {"currentPage": currentPage, "pageSize": pageSize},
    converter: (data) => PageMoment.fromJson(data),
  );
}

Future<bool> addMomentCommentApi(int id, String content) {
  return HttpUtil().post<bool>("/moment/$id/comment", data: content);
}

Future<bool> addMomentLikeApi(int id) {
  return HttpUtil().post<bool>("/food/moment/$id/like");
}

Future<bool> deleteMomentLikeApi(int id) {
  return HttpUtil().delete<bool>("/food/moment/$id/like");
}
